$(function() {

	$('#li_dbak').addClass('active open');
	$('#backupfile').addClass('active');

	clicktable = function(row) {
		// console.log(row);
		$('#tbody').attr('name',row.id);
		
		$.ajax({
			type : 'post',
			url : 'projectselect',
			dataType : 'text',
			data : {
				"project" : row.id
			},
			success : function(msg) {
				var data = JSON.parse(msg);
				//console.log(data);

				var str = '';
				for ( var p in data) {
					str += '<tr><td>' + data[p].name + '</td>' 
							+ '<td>'+data[p].size+' KB </td>'
							+ '<td>' + data[p].date + '</td>'
							+ '<td><i class="icon-folder-open" onclick="download(this)"></i></td></tr>';
				}
				$('#tbody').html(str);
			},
			error : function(msg) {
				console.log('failed');
			}
		});
	}

	download =function(file){
		var fi=$(file).parent().parent().children(':first').html();
		var project=$('#tbody').attr('name');
		
		console.log(project);
		console.log(fi);
		
		var a = document.createElement('a');
		var url = 'backupdownload?project='+project+'&file='+fi;
		a.href=url;
		a.click();
	}
	
	
	var first = $('#nodetable').children(":first").get(0);
	clicktable(first);

});